import request from '../utils/request';
import qs from 'qs';

export async function fetchAds() {
  return request('/ecs/shop/index/ad.action', {
  	headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
	 }
  });
}

export async function fetchHots() {
	return request('/ecs/goods/list.action?page=1&pageSize=12', {
		headers: {
	      'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}


export async function fetchProductionDetail(goodsInfo) {
	return request(`/ecs/goods/detail.action?goodsId=${goodsInfo && goodsInfo.pid}`, {
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}

export async function searchProduction(searchParam) {
	return request(`/ecs/goods/list.action?${qs.stringify(searchParam, {arrayFormat: 'brackets'})}`, {
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}

export async function addCart(searchParam) {
	return request(`/ecs/cart/add.action`, {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify(searchParam)
	})
}

export async function getBrandDetail(searchParam) {
	return request(`/ecs/brand/detail.action?${qs.stringify(searchParam, {arrayFormat: 'brackets'})}`, {
		headers: {
			'Content-Type': 'application/json'
		}
	})
}